using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Devonline.Identity.Admin.Controllers;

[Authorize(Roles = GROUP_MAINTAINERS)]
public class DiagnosticsController : Controller
{
    public async Task<IActionResult> Index()
    {
        var localIpAddress = HttpContext.Connection.LocalIpAddress?.ToString();
        var remoteIpAddress = HttpContext.Connection.RemoteIpAddress?.ToString();
        ArgumentNullException.ThrowIfNull(localIpAddress);
        var localAddresses = new string[] { "127.0.0.1", "::1", localIpAddress };
        if (!localAddresses.Contains(remoteIpAddress))
        {
            return NotFound();
        }

        var model = new DiagnosticsViewModel(await HttpContext.AuthenticateAsync());
        return View(model);
    }
}